#!/bin/bash
usage() { echo "Usage: $0 [-u <url>]" 1>&2; exit 1; }

# alternative url (for China mainland)
url="https://dl.l4d2lk.cn/L4D2/Custom%20Maps/"
# url="http://sirpleaseny.site.nfoservers.com/map/"

while getopts ":u:" o; do
    case "${o}" in
        u)
            url=${OPTARG}
            ;;
        *)
            usage
            ;;
    esac
done
shift $((OPTIND-1))

mapslist=(
    2019.zip
    ArenaOfTheDead2.zip
    BackToSchool.zip
    BloodTracks.zip
    BloodyMoors.zip
    CarriedOff.zip
    City17.zip
    CityOfTheDead.zip
    DarkBlood2.zip
    DarkCarnivalRemix.zip
    Daybreak.zip
    DeadBeforeDawnDC.zip
    DeadbeatEscape.zip
    DeathSentence.zip
    DetourAhead.zip
    DiescraperRedux.zip
    DropDeadGorges.zip
    EnergyCrisis.zip
    FatalFreight.zip
    FloodCenter.zip
    HardRainDownpour.zip
    HauntedForest.zip
    HeavenCanWait2.zip
    HighwayToHell.zip
    IHateMountains2.zip
    LeftBehind.zip
    One4Nine.zip
    OpenRoad.zip
    Ravenholm.zip
    SuicideBlitz2.zip
    TourOfTerror.zip
    UndeadZone.zip
    UrbanFlight.zip
    Warcelona.zip
    White_Forest.zip
)


COLOR='\033[1;33m'
NC='\033[0m' # No Color

INDEX=0
N=${#mapslist[@]}
rm *.zip
for map in ${mapslist[*]} 
  do
    echo -e "${COLOR}[$INDEX/$N]${NC} Downloading ${map}\n"
    wget $url$map
    echo [$INDEX/$N] Unzipping $map 
    yes | unzip $map
    let INDEX=${INDEX}+1
    rm $map
  done